home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / uucico / uux.c < prev    next >
C/C++ Source or Header  |  1990-05-18  |  3KB  |  186 lines

  1.  
  2. /*
  3.  *  UUX.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/uucico/RCS/uux.c,v 1.1 90/02/02 11:56:20 dillon Exp Locker: dillon $
  6.  *
  7.  *  Copyright 1988 by William Loftus.    All rights reserved.
  8.  *
  9.  *  Example: 1> uux mail-message "burdvax!rmail wpl"
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "version.h"
  16.  
  17. IDENT(".02");
  18.  
  19. char user[128];
  20. char file_name[128];
  21. char command[128];
  22.  
  23. char exec_file[128];
  24. char x_exec_file[128];
  25. char command_file[128];
  26. char data_file[128];
  27. int seq;
  28.  
  29. char path[128];
  30.  
  31. void GetTo();
  32. void GetSubject();
  33.  
  34. #define TRUE 1
  35. #define FALSE 0
  36.  
  37. int
  38. brk()
  39. {
  40.     return(0);
  41. }
  42.  
  43. void
  44. main(argc, argv)
  45. int argc;
  46. char **argv;
  47. {
  48.     int error;
  49.     char *up = FindConfig(USERNAME);
  50.  
  51.     onbreak(brk);
  52.     if (up == NULL) {
  53.     printf("couldn't find domain entry for %s\n", USERNAME);
  54.     exit(1);
  55.     }
  56.     strcpy(user, up);
  57.  
  58.     getcwd(path,128);
  59.     chdir(GetConfigDir(UUSPOOL));
  60.     if (argc == 3) {
  61.     strcpy(file_name, argv[1]);
  62.     strcpy(command, argv[2]);
  63.     } else {
  64.     printf("Usage: uux file-name command\n");
  65.     printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
  66.     chdir(path);
  67.     exit(1);
  68.     }
  69.     seq = GetSequence(4);
  70.     if (seq >= 0)
  71.     error = Queue();
  72.     UnLockFile(exec_file);
  73.     UnLockFile(x_exec_file);
  74.     UnLockFile(command_file);
  75.     UnLockFile(data_file);
  76.     chdir(path);
  77.     if (seq < 0 || error < 0)
  78.     exit(1);
  79. }
  80.  
  81. Queue()
  82. {
  83.     FILE *fp;
  84.     char system_name[32];
  85.     int bang;
  86.     int error;
  87.  
  88.     bang = (int)strchr(command,'!');
  89.     bang = bang - (int)command;
  90.  
  91.     strncpy(system_name,command,bang);
  92.  
  93.     system_name[bang] = '\0';
  94.  
  95.     if (!is_in_L_sys_file(system_name)) {
  96.     printf ("System \"%s\" not in L.sys file.\n", system_name);
  97.     return(-1);
  98.     }
  99.  
  100.     system_name[7] = '\0';
  101.  
  102.     sprintf(exec_file,"D.%sX%04d", system_name, seq++);
  103.     sprintf(x_exec_file,"X.%sX%04d", system_name, seq++);
  104.     sprintf(command_file,"C.%sA%04d", system_name, seq++);
  105.     sprintf(data_file,"D.%sB%04d", system_name, seq);
  106.  
  107.     LockFile(exec_file);
  108.     LockFile(x_exec_file);
  109.     LockFile(command_file);
  110.     LockFile(data_file);
  111.  
  112.     fp = fopen(exec_file,"w");
  113.     if (fp) {
  114.     fprintf(fp,"U %s\n", user);
  115.     fprintf(fp,"F %s\n", data_file);
  116.     fprintf(fp,"I %s\n", data_file);
  117.     fprintf(fp,"C %s\n", (char *)command + bang + 1);
  118.     fclose(fp);
  119.     } else {
  120.     perror(exec_file);
  121.     return(-1);
  122.     }
  123.  
  124.     fp = fopen(command_file,"w");
  125.     if (fp) {
  126.     fprintf(fp,"S %s %s %s - %s 0666\n",
  127.         data_file,
  128.         data_file,
  129.         user,
  130.         data_file
  131.     );
  132.     fprintf(fp,"S %s %s %s - %s 0666\n",
  133.         exec_file,
  134.         x_exec_file,
  135.         user,
  136.         exec_file
  137.     );
  138.     fclose(fp);
  139.     } else {
  140.     perror(command_file);
  141.     return(-1);
  142.     }
  143.     chdir(path);
  144.     error =  Copy(file_name, data_file);
  145.     chdir(GetConfigDir(UUSPOOL));
  146.     return(error);
  147. }
  148.  
  149. /*
  150.  * Read the control file and grab a few parameters.
  151.  */
  152.  
  153. Copy(from, to)
  154. char *from;
  155. char *to;
  156. {
  157.     FILE *fd;
  158.     FILE *td;
  159.     int c;
  160.     static char to_buf[128];
  161.  
  162.     fd = fopen(from, "r");
  163.     if (!fd) {
  164.     printf("Could not open %s.\n", from);
  165.     perror(from);
  166.     return(-1);
  167.     }
  168.  
  169.     strcpy(to_buf, MakeConfigPath(UUSPOOL, to));
  170.  
  171.     td = fopen(to_buf, "w");
  172.     if (!td) {
  173.     printf("Could not open %s.\n", to_buf);
  174.     perror(to);
  175.     return(-1);
  176.     }
  177.     while ((c = fgetc(fd)) != EOF) {
  178.     fputc((char)c, td);
  179.     }
  180.     fclose(fd);
  181.     fclose(td);
  182.     return(1);
  183. }
  184.  
  185.  
  186.